package com.dingreading.cloud.mall.service.impl;

import com.dingreading.cloud.mall.entity.table.WebImageTableDef;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.dingreading.cloud.mall.entity.WebImage;
import com.dingreading.cloud.mall.mapper.WebImageMapper;
import com.dingreading.cloud.mall.service.WebImageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2024-08-21
 */
@Service
public class WebImageServiceImpl extends BaseServiceImpl<WebImageMapper, WebImage, WebImageTableDef> implements WebImageService {

    @Override
    protected WebImageTableDef getTable() {
        return WebImageTableDef.webImage;
    }

    @Override
    public List<WebImage> getByTypeIdAndEnabled(Integer typeId, Integer enabled) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.typeId.eq(typeId));
        if (null != enabled)
            condition.and(table.enabled.eq(enabled));

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .orderBy(table.orderNum.asc());

        return getMapper().selectListByQuery(wrapper);
    }
}
